
local locplayer = ac.player.self

local slots = {9,10,11,12,5,6,7,8,1,2,3,4}
ac.game:event '动画-获得符文装备'(function(_,player,temp,time)
    local hero = player.hero
    local idx1 = slots[temp.slotid]
    local idx2 = #hero.items + 1
    if player:is_self() then
        --运动动画
        local panel1 = ac.console.abilitydetail[idx1]
        local panel2 = ac.console.itemdetail[idx2] or ac.console.itemdetail[1]
        local icon = panel1:copy_temp_icon()
        local x,y = panel2:get_real_position()
        icon:set_normal_image(temp.art)
        icon:add_ani_tween({x,y,panel2.w,panel2.h},time,'三元出')
    end
end)


local card_index = 0
local function create_card(state,temp)
    local name = ('%s碎片%s'):format(temp.name,#temp.card_list+1)
    local data = {}
    card_index = card_index + 1

    data.skill_type = "passive"
    data.skill_class = '符文碎片'
    data.name = name
    data.index = card_index
    data.bind_name = temp.name
    data.art = temp.art
    data.state = state
    data.tip = ('%s|n|n[%s]|n%s'):format(atts_tip2(state),temp.title or temp.name,temp.abi_tip)
    data.jb = function(self)
        local card = locplayer.fw_card
        local count = card and card:get(self.bind_name) or 0
        return ('%s(%s/3)'):format(self.bind_name,count)
    end

    ac.lni('skill',name,data)
    return name
end


local fw_list = {}
local params = load_excel('符文装备.xlsx','投放数值')
local main_attr = {4000,6000,10000}
--[初始洗练词条]
local entry_set = {2,3,4}
local exiocns = {
    [[core\边框\白.blp]],
    [[core\边框\绿.blp]],
    [[core\边框\蓝.blp]],
    [[core\边框\紫.blp]],
    [[core\边框\黄.blp]],
}
for _,temp in ipairs(load_excel('符文装备.xlsx','预设效果')) do
    local name = temp.name
    if name then
        local lv = temp.lv or 1
        local entry = {}
        local main_sx = main_attr[lv]
        local pz = temp.item_pz or 1

        for a=1,3 do
            local key = temp['词条'..a]
            local num = key and params[key][lv]
            if key and num then
                entry[#entry + 1] = {key,num}
            end
        end

        temp.main_sx = main_sx
        temp.abi_tip = ''
        temp.item_type = 'campaign'
        temp.item_class = '符文装备'
        temp.entry = entry
        temp.item_level = 1
        temp.max_level = 9
        temp.entry_count = entry_set[pz]
        temp.tip = [['abi_tip'属性：|n'base_tip'|n'up_tip''xl_tip''ex_tip']]
        temp.up_tip = function(self)
            if self.item_level<self.max_level then
                return ('|n点击花费|cffffff00%s金币|r升级'):format(self.gold)
            end
            return ('|n使用|cff00ff00吞噬石|r吞噬装备')
        end
        --每级效果
        temp.set_item_level = function(self,level)
            local hero = self.owner

            --[基础]
            local state = {}
            for a,da in ipairs(self.entry) do
                local key = da[1]
                local num = da[2]
                state[#state + 1] = {key,num * (1 + level*0.2)}
            end
            --local rate = level*(level+1)/2 * 0.06 + 0.1
            local rate = (0.1 + 0.1*level)
            state[#state + 1] = {self['属性'],self.main_sx * rate}
            state[#state + 1] = {'基础攻击',self.main_sx * rate/2}
            
            load_item_state(hero,self.state,-1)
            load_item_state(hero,state,1)
            
            --self.exiocn = exiocns[level] or exiocns[#exiocns]
            self.item_level = level
            self.state = state
            self.gold = level * 1000
            self.base_tip = atts_tip2(state)
            self:set_count(level)
            
            --[洗练]
            local state = self._xl_state or {}
            load_item_state(hero,state,-1)
            for a=1,self.entry_count do
                if level>a then
                    state[a] = state[a] or self:random_entry()
                end
            end
            load_item_state(hero,state,1)

            local tips = self:update_xl()
            for a=1,self.entry_count do
                if state[a]==nil then
                    tips[a] = ('|cff999999随机词条(Lv%0.f解锁)|r'):format(a+1)
                end
            end
            self._xl_tips = table.concat(tips,'|n')
            self._xl_state = state
            
        end

        temp.on_init = function(self)
            self:set_item_level(self.item_level)
        end

        ac.lni('item',name,temp)
        ac.item(name)

        fw_list[#fw_list + 1] = temp

        --符文抽取
        local card_list = {}
        temp.card_list = card_list

        local temp = ac.item.new(name)
        temp.abi_tip = format_obj(temp,temp.abi_tip)
        for a,da in ipairs(entry) do
            local key = da[1]
            local num = da[2]
            local state = {}
            state[#state + 1] = {temp['属性'],temp.main_sx/20}
            state[#state + 1] = {key,num}
            card_list[#card_list + 1] = create_card(state,temp)
        end
        local state = {}
        state[#state + 1] = {temp['属性'],temp.main_sx/20}
        state[#state + 1] = {'基础攻击',temp.main_sx/20}
        card_list[#card_list + 1] = create_card(state,temp)
    end
end

function get_fw_list()
    return table.copy(fw_list)
end


ac.game:event '单位-添加技能'(function(_,hero,skill)
    if skill.skill_class=='符文碎片' then
        for _,da in ipairs(skill.state) do
            local key = da[1]
            local num = da[2]
            skill:gc(hero:add(key,num))
        end
    end
end)




ac.wait(10,function()
    local test_data1 = {}
    for _,data in ipairs(fw_list) do
        test_data1[#test_data1 + 1] = ac.item.new(data.name)
    end
    ac.game:notify('测试-注册数据','符文装备',test_data1,function(_,player,name)
        local hero = player.hero
        if hero then
            hero:add_item(name)
        end
    end)


end)